// pages/membuy/membuy.js
const app=getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    id:0,
    vip:'',
    price:'',
    alltime: [
      {time:'一年会员',price:'398'},
      {time:'二年会员', price: '500'},
      {time:'三年会员', price: '998'},
    ]
  },
  dianjitime: function (e) {
    var id = e.currentTarget.dataset.id;  //获取自定义的ID值  
    this.setData({
      id: id
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  payment:function(){
    var that=this;
    var id=that.data.id;
    var uid=wx.getStorageSync("uid");
    var openid = wx.getStorageSync("openid");
    this.setData({
      vip: that.data.alltime[id].time,
      price: that.data.alltime[id].price
    })
    var vip=that.data.vip
    var price = that.data.price
    wx.request({   
      url: app.data.Url + 'order/rechargePay',
      data: {
        uid: wx.getStorageSync('uid'),
        money: price
      },
      method: 'post',
      success: function (res) {
        console.log(res.data.data.weixin);
        wx.requestPayment({
          'timeStamp': res.data.data.weixin.timeStamp,
          'nonceStr': res.data.data.weixin.nonceStr,
          'package': res.data.data.weixin.package,
          'signType': 'MD5',
          'paySign': res.data.data.weixin.paySign,
          'success': function (ress) {
            wx.showToast({
              title: '支付成功',
              icon: 'success',
              duration: 1500
            })
            wx.request({
              url: 'https://www.135k.com/addons/sd_humans/tp/index.php/users/vip',
              data:{
                id:id,
                uid:uid, 
                money:price,
                vip:vip  
              },
              success:function(res){
                console.log(res);
                var step=res.data
                wx.setStorageSync("step", res.data)
                setTimeout(function () {//确认之后跳转的页面
                  wx.switchTab({
                    url: '../my/my'
                  })
                }, 1500);
              }

            })
        
          },
          'fail': function (res) {
          },
          'complete': function (res) {
            console.log(res, 'cccccc');
          }
        })
        // console.log(res);
      }
    })  
  },
  onLoad: function (options) {
  
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})